﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess.Operate
{
    public class DA_Log_Inherit:DA_Log_Operate
    {
        #region 查询日志
        /// <summary>
        /// 查询日志
        /// </summary>
        /// <returns></returns>
        public DataSet FindLibrary(string sProjectID)
        {

            string sSql = "select Log_EmployeeID,Log_EmployeeName,Log_OperateTime,(select Operate_Name from t_Dic_Project_Operate where Operate_ID=Log_OperateID) as Operate_Name," +
                        "(select OperateModule_Name from t_Dic_Project_OperateModule where OperateModule_ID=Log_OperateModuleID) as OperateModule_Name" +
                        " from t_Log where Log_OperateModuleMainID=@sProjectID order by Log_OperateTime desc";
            SqlCommand cmdToExecute = new SqlCommand();
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
            DataSet ds = new DataSet();

            cmdToExecute.CommandText = sSql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = _mainConnection;

                cmdToExecute.Parameters.Add(new SqlParameter("@sProjectID", sProjectID));

                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                adapter.Fill(ds);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmdToExecute.Dispose();

                adapter.Dispose();
            }

            return ds;
        }
        #endregion
    }
}
